package com.example.response;

import com.example.utils.ResultCodeUtil;
import lombok.Getter;

import java.io.Serializable;


/**
 * ajax请求返回Json格式数据的封装
 */
@Getter
public class AjaxJson implements Serializable {
    Integer code;
    String msg;
    Object data;

    public AjaxJson(ResultCodeUtil code, String msg, Object data) {
        this.code = code.getCode();
        this.msg = msg;
        this.data = data;
    }

    public AjaxJson(ResultCodeUtil code, String msg) {
        this.code = code.getCode();
        this.msg = msg;
    }

    public AjaxJson(ResultCodeUtil code) {
        this.code = code.getCode();
        this.msg = code.getMessage();
    }

    public AjaxJson(ResultCodeUtil code, Object data) {
        this.code = code.getCode();
        this.msg = code.getMessage();
        this.data = data;
    }

    public static AjaxJson error(ResultCodeUtil code, String msg) {
        return new AjaxJson(code, msg);
    }

    public static AjaxJson error(ResultCodeUtil code) {
        return new AjaxJson(code);
    }

    public static AjaxJson error(ResultCodeUtil code, String msg, Object data) {
        return new AjaxJson(code, msg, data);
    }

    public static AjaxJson ok(ResultCodeUtil code, Object data) {
        return new AjaxJson(code, data);
    }

    public static AjaxJson ok(ResultCodeUtil code) {
        return new AjaxJson(code);
    }

    public static AjaxJson ok(ResultCodeUtil code, String msg) {
        return new AjaxJson(code, msg);
    }

    public static AjaxJson ok(Object data) {
        return new AjaxJson(ResultCodeUtil.SUCCESS, data);
    }
    public static AjaxJson ok(ResultCodeUtil code,String msg,Object data){
        return new AjaxJson(code, msg, data);
    }

    public static AjaxJson ok() {
        return new AjaxJson(ResultCodeUtil.SUCCESS);
    }
}